home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
batchut
/
setpgms.zip
/
SETREAD.ASM
< prev
next >
Wrap
Assembly Source File
|
1986-12-26
|
14KB
|
371 lines
page 64,132
;Copyright 1986, Arnold B. Krueger
;All rights reserved. Contact "ARNY KRUEGER"
;at the EXEC-PC BBS (414-964-5160) for permission
;to use commercially.
;SETREAD reads the keyboard and places what it reads into the
;environment variable READSTR. Usage is:
;
; SETREAD [flags] [name] [flags]
;
; "name" is the name of the environment variable set.
; if none is supplied then READSTR is used.
;
;flags are: /U - make input upper case
; /L - make input lower case
; /F - read a single keystroke
; honors typewriter keys, f1-f9
;
;You can then refer to the named string in .BAT files
; using its name delimited by percent signs ('%').
;
;For example:
; Echo name of program to run:
; SETREAD
; echo running: %readstr%
; %readstr%
;errorlevels are:
; 0 if all goes well
; 0 if the environment is out of space
; (an error message will be typed by DOS)
; 1 not at DOS 2.0 or above
; 2 for SETREAD detected errors:
; (an error message will be typed)
; 3 for reading a null string
; (no error message or alteration
; of the environment)
; 4 for ctrl-break
; (no error message or alteration
; of the environment)
code_seg segment para public
assume cs:code_seg,ds:code_seg,ss:code_seg,es:code_seg
extrn env_set:near
org 80h
psp_parml db ? ;length of parms
psp_parm db ? ;actual parms
org 100h ; .COM file format
main: jmp main_start ; Skip around data declarations
copyright db 'Copyright 1986, Arnold B. Krueger GPW, MI 48236'
beep equ 07
cr equ 13
escape equ 27
lf equ 10
set_string db 'READSTR'
set_length equ $-set_string
release_error db 1,'Need at least DOS 2.0 to run SETREAD',cr,lf,'$'
set_error db 2
crlf db cr,lf,'$'
scan_for_word proc near ;proc to scan es:di for contents of AX
; CX is length
;at exit if found: es:di points to word
; cf is set
; cx as at entry
; not found es:di points to string
; cf not set
push cx ; cx as at entry
push di
cmp cx,2
jb scan_for_miss
scan_for_loop: scasw ;compare word to AX
jz scan_for_hit
dec di ;back up a byte
loop scan_for_loop
pop di ;missed it
pop cx
scan_for_miss:
clc ;set not found flag
jmp scan_for_exit
scan_for_hit: ;back up over string
dec di
dec di
pop cx ;actually di data
pop cx
stc ;set found flag
scan_for_exit: ret
scan_for_word endp
scan_switches_switch db 0 ;flag byte checked, as follows:
scan_switches_switches: ;list of switches searched for
db '/u'
switch_upper equ 40h ;translate to upper case
db switch_upper
db '/l'
switch_lower equ 20h ;translate to lower case
db switch_lower
db '/f'
switch_fkey equ 10h ;accept as input a single keystroke
db switch_fkey
switch_list_length equ $-scan_switches_switches
switch_count equ switch_list_length / 3
scan_switches proc near ;scan parameters for switches
push ax ; Switches are defined above as word of text
push cx ; and byte containing switch bit(s)
push di ; Switch text is blanked out of parameter
push es ; If switch byte has hi bit turned on,
push si ; switch bit(s) are turned off
mov cx,switch_count ;number of switches to test for
push cs ;get PSP address
pop es ; in ES
mov si,offset scan_switches_switches
scan_switches_loop:
push cx ;save loop counter
lodsw ;get flag to scan for into AX
cmp ah,'Z' ;are we scanning for lower case?
ja scan_lower ;if so, great
;protect me from sloppy programmers (!)
or ah,32 ;if not, make lower.
scan_lower:
mov di,offset psp_parm ;get where to scan
xor cx,cx
mov cl,[psp_parml] ;get length of parm string
jcxz scan_switches_none ;if no parms, no flags set
call scan_for_word ;scan for indicated flag
jc scan_case ;if we got it, modify switches
and ah,255-32 ;make upper case
call scan_for_word ;scan for indicated flag in upper case
scan_case:
lodsb ;put flag byte value in AL
jnc scan_switches_loop_inc ;skip including it, if not found
test al,80h ;if hi bit of flag is off
jz scan_turn_on ;we are turning switch bits on
;otherwise, turn them off by:
xor al,0ffh ;invert bits in flag
and scan_switches_switch,al ;and use to turn off switch bits
jmp scan_blank
scan_turn_on:
or scan_switches_switch,al ;add into switch bit into switch byte
scan_blank:
mov es:[di],' ' ;blank out parm
scan_switches_loop_inc:
pop cx ;restore loop counter
loop scan_switches_loop
jmp scan_switches_exit
scan_switches_none:
pop cx ;clean up stack
scan_switches_exit:
pop si
pop es
pop di
pop cx
pop ax
ret
scan_switches endp
read_byte proc near ;read single byte into area at ds:di
;return length of symbol in cx
push ax ;save registers
push dx
read_byte_in:
mov ah,08h ;dos int to read a key, no echo
int 21h
cmp al,0 ;scan code returned?
jnz